<template>
  <div class="app-personalQueryresuly">
    <approval-user-all :approval-user="approvalUser"></approval-user-all>
    <el-table style="marginTop:20px;" :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
        <el-table-column type="index" width="50" label="序号"></el-table-column>
        <el-table-column label="业务名称"  align="center">
          <template slot-scope="scope">
            {{ scope.row.approvalKey | mapLabel('approvalKey')}}
          </template>
        </el-table-column>
        <el-table-column label="申请时间"  align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.createTime">{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="created_at" label="审批时间" width="200">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span v-if="scope.row.createTime">{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="审批状态"  align="center">
          <template slot-scope="scope">
            {{ scope.row.status | mapLabel('approvalStatus')}}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="250" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleView(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table> 
      <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
          :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
  </div>
</template>
<script>
import ApprovalUserAll from "../components/ApprovalUserAll";
import { queryPersonalApprovals, queryPersonalInfo } from "@/api/approval";
import { closeCollectTag, getAgeEtc } from "@/utils/tools";

export default {
  components: {
    ApprovalUserAll
  },
  data() {
    return {
      approvalUser: null,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        size: 10,
        idCard: null,
        sort: "+id"
      }
    };
  },
  mounted() {
    if (this.$route.query.idCard) {
      this.listQuery.idCard = this.$route.query.idCard;
      this.fetchData();
    } else {
      this.listLoading = false;
    }
  },
  methods: {
    fetchData() {
      let ageEtc = getAgeEtc(this.listQuery.idCard);
      queryPersonalInfo(this.listQuery.idCard).then(response => {
        this.approvalUser = response.data;
        this.approvalUser.age = ageEtc.age;
      });
      queryPersonalApprovals(this.listQuery).then(response => {
        this.list = response.data.records;
        this.total = response.data.total;
        this.listLoading = false;
      });
    },
    handleFilter() {
      if (this.listQuery.queryTime.length > 1) {
        this.listQuery.startTime = this.listQuery.queryTime[0].getTime() / 1000;
        this.listQuery.endTime = this.listQuery.queryTime[1].getTime() / 1000;
      }
      this.listQuery.page = 1;
      this.fetchData();
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.fetchData();
    },
    handleView(row) {
      this.$router.push({
        name: "approvalInfo",
        query: { action: "view", id: row.id, approvalKey: row.approvalKey }
      });
      closeCollectTag(this);
    }
  }
};
</script>
<style scoped>
.pagination-container {
  margin-top: 25px;
  margin-bottom: 25px;
  display: flex;
  justify-content: flex-end;
  height: 50px;
}
.app-personalQueryresuly {
  padding-right: 20px;
  padding-left: 20px;
  padding-top: 20px;
}
</style>

